/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package race.component;

import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.TiledLayer;
import race.util.BackgroundUtil;

/**
 *
 * @author BBXP
 */
public class BackgroundLayer extends TiledLayer{
    public BackgroundLayer(Image tiles, int cols, int rows, int[] mapping){
        super(cols, rows, tiles, BackgroundUtil.TILE_WIDTH, BackgroundUtil.TILE_HEIGHT);
        setBackGround(mapping);
    }

    private void setBackGround(int[] mapping){
        int col, row;
        int cols = this.getColumns();
        int rows = this.getRows();
        for(int i = 0; i < cols * rows; i++){
            col = i % cols;
            row = (i - col) / cols;
            setCell(col, row, mapping[i]);
        }
    }
}
